var account = $api.getStorage("account");

	apiready = function(){
		
		init();
	};
	
	
	function init() {
		var year = $api.byId("year").value;
		var month = $api.byId("month").value;
		
		var yearmonth = "";
		
		if (year != '' && month != '') {
			yearmonth = year + '-' + month;
		}
		
		if (year == '' || month == '') {
			$api.byId("date_text").innerHTML = "全部账单";
		} else {
			$api.byId("date_text").innerHTML = yearmonth;
		}
		
		api.showProgress({
	        title: '加载中...',
	        modal: false
	    });
	    
	    var getUrl = serviceUrl+"/app/propertybill?account=" + account + "&yearmonth=" + yearmonth;
		api.ajax({
	        url: getUrl,
	        method: 'get',
	        cache: false,
	        timeout: 20,
	        headers: {
	            "Content-type": "application/json;charset=UTF-8"
	        }
	    }, function (ret, err) {
	    	 if (ret) {
	        	var list = "";
	        	var yearmonth = "";
	        	var result = ret;
	        	var resultT = ret;
	        	
	        	if (result.length > 0) {
	        	
					for (var i in result) {
						
						if (result[i].yearmonth != yearmonth) {
						
							list += '<div class="am-u-sm-12" style="background:#efefef;border-radius:5px;padding:2px;color:red;">';
							list += result[i].yearmonth;
							list += '</div>';
							
							for (var j in resultT) {
							
								if (result[i].yearmonth == resultT[j].yearmonth) {
								
									list += '<div class="am-u-sm-12" style="padding:8px;">';
									
									list += '<div class="am-u-sm-4" style="padding:0px;">';
									list += result[j].name;
									list += '</div>';
									
									list += '<div class="am-u-sm-4" style="padding:0px;">';
									list += '￥'+result[j].qsaccount;
									list += '</div>';
									
									list += '<div class="am-u-sm-4" style="padding:0px;">';
									
									if (result[j].status == '已交') {
									    list += '<span style="color:green">' + result[j].status + '</span>';
									}
									else {
										list += '<span style="color:red">' + result[j].status + '</span>';
									}
									
									list += '</div>';
									list += '</div>';
								}
							}
							
							yearmonth = result[i].yearmonth;
						}
						
					}
					
				} else {
					
					list += '<div class="am-u-sm-12" style="margin:0px;background: white;padding:10px;text-align:center;">亲，您还没账单数据呢...</div>';
				}
				
				$api.byId("bill_list").innerHTML = list;
	        	
	        } else {
	            api.alert({msg: err.msg});
	        }
	        api.hideProgress();
	    });
	}
	

